<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        入库单
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>物料信息</cite></a>
            <a><cite>材料入库</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                            style="line-height:30px">ဂ</i></a>
    </div>
    <div class="main_box">
        <div class="panel-heading">
            <ul class="nav nav-tabs" id="navTabs">
                <li class=""><a class="receivePane" data-tab="" href="material_in.html">入库记录</a></li>
                <li class="active"><a class="payPane" data-tab="" href="material_in_list.html">入库单</a></li>
                <li style="float: right;width: 162px" class="dropdown">
<!--                    <a href="javascript:void(0)" onclick="admin_add('添加','supplier_add.html')" class="dropdown-toggle"-->
<!--                       data-toggle="dropdown" role="button"><b>添加出库</b></a>-->
                    <a href="javascript:void(0)" onclick="admin_add1('添加入库','material_in_add.html',1200,600)">添加入库</a>
                </li>
            </ul>
        </div>
    </div>

    <form class="layui-form x-center">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item" style="padding-left: 7%">
<!--                <label class="layui-form-label">入库来源</label>-->
<!--                <div class="layui-input-inline">-->
<!--                    <input  autocomplete="off"  type="text" class="layui-input" name="joinWarehouseType" placeholder="入库来源">-->
<!--                </div>-->

                <label class="layui-form-label">入库来源</label>
                <div class="layui-input-inline">
                    <select name="joinWarehouseType" lay-search="" id="joinWarehouseType">
                        <option value="">选择入库来源</option>
                    </select>
                    <!--                    <input  autocomplete="off"  type="text" class="layui-input" name="joinWarehouseType" placeholder="入库来源">-->
                </div>
                <label class="layui-form-label">库房名称</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="warehouseName" placeholder="库房名称">
                </div>

                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索</button>
                    <button type="reset" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe666;</i>重置</button>
                </div>

            </div>
        </div>
    </form>


    <div class="layui-card-body">

        <table class="layui-table" id="test" lay-filter="test">
        </table>
    </div>
    <br><br><br><br><br><br>
</div>
</body>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-xs" style="background: red" lay-event="del">删除</a>

    {{#  if(d.joinTypeName === "员工采购"){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="repealJoin">撤销</a>
    {{#  } }}

</script>


<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script type="text/javascript" src="../../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        var form = layui.form;
        okLoading.close($);
    });
</script>


<script>

    layui.use(['table','laydate', 'form', 'laytpl'],
        function () {
            var laydate = layui.laydate;
            var form = layui.form;
            var table = layui.table;
            laytpl = layui.laytpl;
            getDictionaryValue();
            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#end' //指定元素
            });

        var t1 = table.render({
            elem: '#test',
            url: $baseUrl + 'kf/partsJoinWarehouse/getJoinWarehouseForm',
            where: {
                userId: $userId,
            },
            headers: {
                token: $token
            }
            , toolbar: '#toolbarDemo',

            cols: [
                [
                    {
                        type: 'numbers',
                        title: '序号',
                        width: '5%',
                        fixed: 'left'
                    },
                    {
                        field: 'joinTypeName',
                        title: '入库来源',
                    },
                    {
                        field: 'buyerName',
                        title: '采购人员',
                    },
                    {
                        field: 'warehouseName',
                        title: '入库库房',
                    },
                    {
                        field: 'joinerName',
                        title: '入库人员',
                    },
                    {
                        field: 'joinTime',
                        title: '入库日期',
                    },
                    {
                        field: 'status',
                        title: '操作',
                        // templet: '#barDemo',
                        fixed: 'right',
                        width: '15%',
                        templet: function (item) {
                            // <a className="layui-btn layui-btn-xs" lay-event="detail">详情</a>
                            var html = '';
                            html += '<a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>'
                            html += '<a class="layui-btn layui-btn-xs" style="background: red" lay-event="del">删除</a>'
                            if (item.dataType === '0') {
                                html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="repealJoin">撤销</a>';
                            }
                            if (item.dataType === '1') {
                                setTimeout(() => {
                                    $('.layui-table-body table tbody tr[data-index=' + (Number(item.LAY_INDEX) - 1) % 10  + ']').css('background', '#ff000066')
                                }, 111)
                            }

                            return html;
                        }
                    }]
            ],
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'size',
            },
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,
                statusCode: 0 //规定成功的状态码，默认：0
                ,
                msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,
                dataName: 'data.JoinWarehouseFormData', //规定数据列表的字段名称，默认：data
            },
            id: 'test',
            page: true,
            height: 'auto',
            even: true,
            done: function (res, curr, count) {
                //是否有权限或权限是否失效
                authorizeState();
            }
        });


        form.on('submit(sreach)', function(data) {
            var joinWarehouseType = data.field.joinWarehouseType;
            var warehouseId = data.field.warehouseId;
            var warehouseName = data.field.warehouseName;

            table.reload('test', {
                where: { //设定异步数据接口的额外参数，任意设
                    joinWarehouseType: joinWarehouseType,
                    // warehouseId: warehouseId,
                    warehouseName: warehouseName,
                },
            });
            return false;
        })


        //监听工具条
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') {
                layer.confirm('是否确认删除？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "kf/partsOutWarehouse/deleteData",
                        data: {
                            userId: $userId,
                            dataId: data.id,
                            partsType: 0,
                            dataType: 1
                        },
                        method: "get",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("删除成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("删除失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });


            } else if (layEvent === 'repealJoin') {
                admin_add2('撤销', 'repeal_join.html?recordId=' + data.id, '95%', '90%')
            }
            else if (layEvent === 'detail') {
                admin_add2('入库单详情', 'stock_in_order_detail.html?recordId=' + data.id, '95%', '90%')
            }
        });

    });

    function reload(value) {
        table.reload('test', {
            where: {
                outWarehouseType: $("select[name=outWarehouseType]").val(),
                warehouseName: $("input[name=warehouseName]").val(),
                outpeName: $("input[name=outpeName]").val(),
                receiverName: $("input[name=receiverName]").val(),
            }
        });
    }

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }

    function admin_add1(title, url, w, h) {
        setTimeout(() => {
            x_admin_show(title, url, w, h);
        }, 400);

    }
    function admin_add2(title, url, w, h) {
        layer.open({
            type: 2,
            area: [w, h],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            offset: ['20px', '20px'],
            title: title,
            content: url
        });
    }

    function getDictionaryValue(){
        $.ajax({
            type:"get",
            url:baseHead + "kf/dictionary/getValue",
            data:{
                userId :$userId,
                dictionaryCode:'Join_warehouse_type'
            },
            headers: {
                "token": $token,
            },
            success:function(res){
                if(res.code === 0){
                    for(var i =0;i < res.data.length;i++){
                        $("#joinWarehouseType").append("<option value=\""+res.data[i].type+"\">"+res.data[i].name+"</option>");
                    }
                    //重新渲染
                    layui.form.render("select");
                }else{
                    layer.msg(res.message);
                }
            }
        });
    }

    setTimeout(() => {

        let form = layui.form;
        //出库类型
        let request = {
            url: 'dictionary/findDictionariesSelect',
            data: {
                userId: $userId,
                dictionaryCode: 'out_warehouse_type'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let d = res.data;
            $.each(d, function (index, item) {
                let opt = $("<option value=" + item.type + ">" + item.name + "</option>");
                $("select[name=outWarehouseType]").append(opt);

            });
            form.render('select');
        });

    }, 300)

</script>

</html>
